package cn.yangliu.nacos.comm.config.security.handler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.yangliu.nacos.comm.enums.GlobalResultCode;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;


/**
 * The interface Security access denied handler.
 *
 * @author 问道于盲
 */
public class SecurityAccessDeniedHandler implements AccessDeniedHandler, SecurityHandler {

    /**
     * Handles an access denied failure.
     *
     * @param request       that resulted in an <code>AccessDeniedException</code>
     * @param response      so that the user agent can be advised of the failure
     * @param authException that caused the invocation
     * @throws IOException      in the event of an IOException
     * @throws ServletException in the event of a ServletException
     */
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response,
                       AccessDeniedException authException)
            throws IOException, ServletException {
        handle(request, response, HttpStatus.FORBIDDEN, GlobalResultCode.ACCESS_TOKEN_NO_AUTHORITY);

    }
}
